﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.AccountProxy;
	import com.wandian.model.UserInfoProxy;
	import com.wandian.model.vo.FaceVo;
	import com.wandian.model.vo.FriendVo;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.TextControl;
	import com.wandian.util.ToolTip;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;

	/**
	* @author long
	* @QQ 108232706
	* @version 1.0
	*/
	public class HornPanel extends Object
	{
		private var facade:ApplicationFacade;
		private var _global:GameData;
		private var _mcPanel:Sprite;
		private var sumLen:int=40;

		public function HornPanel(mcHornPanel:Sprite)
		{
			this.facade=ApplicationFacade.getInstance();
			this._global=GameData.getInstance();
			this._mcPanel=mcHornPanel;
			AddBtn.initBtn(mcHornPanel, CLZNoticeName.HIDE_HORN_PANEL, AddBtn.CLOSE_TWO, "", 3, 4);
			var _loc_2:*=new PlayerVo();
			_loc_2=GameData.copyClass(this._global.userInfo.userVo, _loc_2) as PlayerVo;
			AddBtn.addCurrentFunBtn(this._mcPanel, this.buyInHornHandler, GameData.tip["BUYIN_NAME"], 110, 40, "OtherBtn3"); //确定买入
			AddBtn.addCurrentFunBtn(this._mcPanel, this.okUseHornHandler, GameData.tip["HORN_CALL_NAME"], 163, 193, "Otherbtn"); //发送喇叭
			mcHornPanel["title_txt"].htmlText=GameData.tip["HORN_NAME"];
			this.updatePropNum();
			mcHornPanel["inputTip_txt"].htmlText=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["HORN_INPUT_HORN_TIP"], "NUM1", this.sumLen), "NUM2", "0");
			mcHornPanel["intro_txt"].htmlText=GameData.tip["HORN_INTRO"];
			mcHornPanel["input_txt"].text="";
			Texas.I._mcGameView.stage.focus=mcHornPanel["input_txt"];
			mcHornPanel["input_txt"].addEventListener(Event.CHANGE, this.chageInputHandler);
			return;
		}

		private function buyInHornHandler():void
		{
			var propVo:PropVo=GameData.getPropById(1, 1);
			this.facade.sendNotification(CLZNoticeName.BUYIN_PROP_TIP_WINDOW, propVo);
			return;
		}

		public function updatePropNum():void
		{
			var account:AccountProxy=this.facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			var _loc_2:*=account.getPropNumById(1, 1);
			this._mcPanel["numTip_txt"].htmlText=GameData.replaceStrValue(GameData.tip["HORN_NUM"], "NUM", _loc_2); //拥有喇叭数
			return;
		}

		private function okUseHornHandler():void
		{
			var msg:String=this._mcPanel["input_txt"].text;
			var curLength:int=TextControl.checkStrByte(msg);
			if (this.sumLen - curLength < 0 || curLength == 0)
			{
				this.facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: GameData.tip["ENTER_ERR"]});
				return;
			}
			var account:AccountProxy=this.facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			var hornNum:int=account.getPropNumById(1, 1);
			if (hornNum == 0)
			{
				//发送失败，没有喇叭卡，请移步到商城购买
				this.facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: GameData.tip["HORN_PROP_NOT"]});
				return;
			}
			this.facade.sendNotification(CLZNoticeName.CHAT, {msg: msg, type: 1});
			this.facade.sendNotification(CLZNoticeName.HIDE_HORN_PANEL);
			return;
		}

		private function chageInputHandler(event:Event):void
		{
			var _loc_2:*=TextControl.checkStrByte(this._mcPanel["input_txt"].text);
			var _loc_3:int=40;
			if (_loc_3 - _loc_2 < 0)
			{
				this._mcPanel["inputTip_txt"].htmlText=GameData.replaceStrValue(GameData.tip["HORN_INPUT_HORN_TIP_ERR"], "NUM", _loc_2);
			}
			else
			{
				this._mcPanel["inputTip_txt"].htmlText=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["HORN_INPUT_HORN_TIP"], "NUM1", _loc_3 - _loc_2), "NUM2", _loc_2);
			}
			return;
		}

	}
}
